# -*- python -*-
# ex: set syntax=python:

# This is a sample buildmaster config file. It must be installed as
# 'master.cfg' in your buildmaster's base directory (although the filename
# can be changed with the --basedir option to 'mktap buildbot master').

# It has one job: define a dictionary named BuildmasterConfig. This
# dictionary has a variety of keys to control different aspects of the
# buildmaster. They are documented in docs/config.xhtml .

import sys
sys.path.append('scripts/common')
sys.path.append('scripts/master')
import slavepasswd

# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}

builder_map = {
  'glibc-x86_64-linux': 'glibc-ubuntu-trusty-slave2',
  'glibc-i686-linux': 'glibc-ubuntu-trusty-slave2',
  'glibc-power8-linux': 'fedora22-ppc64-1',
}

builders = sorted(set(builder_map.iterkeys()))
slaves = sorted(set(builder_map.itervalues()))


####### BUILDSLAVES

from buildbot.buildslave import BuildSlave
c['slaves'] = [BuildSlave(slave, slavepasswd.slave_password(), max_builds=1)
               for slave in slaves]

c['slavePortnum'] = 9991

####### CHANGESOURCES

from buildbot.changes.gitpoller import GitPoller
git_poller = GitPoller(
                   repourl='git://sourceware.org/git/glibc.git',
                   pollinterval=120, # seconds
                   workdir='gitpoller-workdir',
)
c['change_source'] = git_poller

####### SCHEDULERS

from buildbot.schedulers.basic import SingleBranchScheduler
from buildbot.schedulers.forcesched import *

c['schedulers'] = []
c['schedulers'].append(SingleBranchScheduler(name='all', branch='master',
                                             treeStableTimer=60,
                                             builderNames=builders))
c['schedulers'].append(ForceScheduler(
                            name="force",
                            builderNames=builders))

####### BUILDERS

from AnnotatedFactory import getGlibcAnnotatedFactory
from buildbot.config import BuilderConfig

c['builders'] = [BuilderConfig(name = builder,
                               slavename = slave,
                               factory = getGlibcAnnotatedFactory())
                 for builder, slave in builder_map.iteritems()]

####### STATUS TARGETS

c['status'] = []

from buildbot.status.html import WebStatus
from buildbot.status.web import authz, auth

auth_user = 'glibc-hackers'
auth_pw = open('authpasswd').read().strip()

authz_cfg = authz.Authz(
    auth=auth.BasicAuth([(auth_user, auth_pw)]),
    gracefulShutdown = False,
    forceBuild = 'auth',
    forceAllBuilds = 'auth',
    pingBuilder = 'auth',
    stopBuild = 'auth',
    stopAllBuilds = 'auth',
    cancelPendingBuild = 'auth'
)
webstatus = WebStatus(http_port=8080, authz=authz_cfg)
c['status'].append(webstatus)


####### PROJECT IDENTITY

c['projectName'] = "glibc"
c['projectURL'] = "http://www.gnu.org/software/libc/"

#c['buildbotURL'] = "http://130.211.48.148:8080/"
# Prettier URL set up as a redirect to the real one above.
c['buildbotURL'] = "http://glibc-build.hack.frob.com/"

####### DB URL
c['db'] = {
    # This specifies what database buildbot uses to store its state.  You can leave
    # this at its default for all but the largest installations.
    'db_url' : "sqlite:///state.sqlite",
}
